<template>
	<view class="contents" :style="'height:'+screenHeight+'px;'">
		<!-- <view class="top">
			<u-subsection :list="list" :current="2" @change="changes" mode="button" active-color="#ffffff"
				button-color="#FF6F86" bg-color="#ffffff"></u-subsection>
		</view> -->

		<view class="middle" v-if="show">
			<view class="body" v-for="(item,index) in orderlist" :key="index">
				<view class="leftf" @click="detail(item)">
					<view class="date">
						<span>{{splitetext(item.djdate)}}</span>
					</view>
					<view class="information">
					<!-- 	<span class="gray">就诊人：<span class="black">{{item.TJName}}</span></span>
						<span class="primary">{{item.VisitTime}}</span> -->
						<span class="gray">体检项目：<span class="black">{{item.tcname}}</span></span>
						<span class="gray">体检日期：<span class="black">{{splitetext(item.djdate)}}</span></span>
					</view>
					<view class="rightbutton">
						<view class="label"  >
							<!-- <span>未支付</span> -->
						</view>
					
					</view>

				</view>
			</view>

		</view>
		<view class="none" v-else>
			<view class="coent">
				<u-empty text="当前暂无记录" mode="data" icon="/static/zwnr.png" icon-size="200">
				</u-empty>
			</view>
		</view>
		<u-modal :show="deleteshow" :showCancelButton="true" :title="title" :content='content' @confirm="confirm()"
			@cancel="deleteshow=false"></u-modal>
		<u-modal :show="showdeletes" :showCancelButton="true" :title="deletetitle" :content='deletecontent'
			@confirm="deletesconfirm()" @cancel="showdeletes=false"></u-modal>
		<u-modal :show="showrefund" :showCancelButton="true" :title="refundtitle" :content='refundcontent'
			@confirm="refundconfirm()" @cancel="showrefund=false"></u-modal>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'

	export default {
		data() {
			return {
				screenHeight: getApp().globalData.screenHeight - 44,
				list: [{
						Status: 0,
						name: '未支付 '
					}, {
						Status: 1,
						name: '已支付'
					},
					{
						Status: 2,
						name: '已完成'
					},
					{
						Status: 10,
						name: '已退款'
					},
					{
						Status: 11,
						name: '已接诊'
					}
				],
				current: 0,
				showdeletes: false,
				deleteshow: false,
				showrefund: false,
				page: 1,
				rows: 20,
				Status: 'all',
				orderlist: [],
				title: '取消预约',
				content: '取消预约之后不可恢复，是否确认',
				deletetitle: '删除预约记录',
				deletecontent: '删除预约记录之后不可恢复，是否确认',
				refundtitle: '退款',
				refundcontent: '退款之后不可恢复，是否确认',
				OrderNumber: '',
				openid: '',
				month: '',
				day: '',
				show: true
			}
		},
		computed: {
			...mapState(['token'], ['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo'])
		},
		onLoad: function(option) {
			console.log("optino", option)
			if (option.current) {
				this.current = option.current
			} else {
				this.current = 0
			}
			
		},
		
		
		
		onShow() {
			if (this.hasLogin) {
				uni.showLoading({
					title: '加载中'
				})
				this.$store.dispatch('getUserInfo');
				this.recordlist()
			} else {
				uni.hideLoading();
				uni.showModal({
					title: '提示',
					content: '登录后才可以操作',
					confirmText: '去登录',
					showCancel: false,
					success: function(res) {
						uni.reLaunch({
							url: '/pages/auth/login'
						})
					}
				});
				return;
			}
		
		},
		
		    onBackPress(event) {
		    	uni.switchTab({
		    		url: '/pages/index/index'
		    	});
		    	return true;
		    },
		methods: {
			detail(OrderId) {
				console.log("OrderId", OrderId)

				uni.navigateTo({
					url:`/pages/MedicalExamination/Health/HealthDetail?tcname=${OrderId.tcname}&zs=${OrderId.zs}&jg=${OrderId.jg}&tjid=${OrderId.tjid}`,
					fail(error) {
						console.log(error)
					}
				})
			},
			getMpWxCode(OrderNumber) {
				uni.login({
					success: async resCode => {
						console.log("rescode", resCode)
						let res = await this.$request('auth', 'getopenid', {
							Code: resCode.code
						});

						if (res.code === 1) {
							console.log("res", res)
							this.appid = res.data.appid;
							this.sessionkey = res.data.session_key;
							this.openid = res.data.openid;
							this.pays(OrderNumber)
						}
					}
				})
			},
			
			// pays(OrderNumber) {
			// 	console.log(OrderNumber)
			// 	this.$request("pay", "pay", {
			// 		OrderNo: OrderNumber,
			// 		openid: this.openid,
			// 	}).then(resto => {
			// 		console.log(resto)
			// 		if (resto.code == 1) {
			// 			uni.showLoading({
			// 				title: '请等待'
			// 			})
			// 			uni.requestPayment({
			// 				provider: 'wxpay',
			// 				timeStamp: resto.data.Timestamp,
			// 				package: resto.data.Package,
			// 				nonceStr: resto.data.Noncestr,
			// 				signType: resto.data.SignType,
			// 				paySign: resto.data.paySign,
			// 				success: (resshree) => {
			// 					console.log(resshree)

			// 					uni.hideLoading();
			// 					this.recordlist()
			// 				},
			// 				fail: (err) => {
			// 					console.log(err)
			// 					uni.hideLoading();
			// 					this.recordlist()
			// 				}

			// 			})

			// 		}

			// 	})

			// },
			splitetext(text) {
				console.log(text)
				let temp = text + ''
				temp = Number.parseInt((temp.split("T")[0].split('-')[1])) + "月" + temp.split("T")[0].split('-')[2] + "日"
				return temp


			},
			changes(index) {
				console.log(index)
				this.current = index
				this.Status = this.list[index].Status
				console.log("this.list[index].Status", this.Status)
				this.recordlist()
			},
			deletesconfirm() {
				//console.log(this.OrderNumber)
				this.$request("Order", "Delete", {
					OrderNo: this.OrderNumber
				}).then(res => {
					if (res.code == 1) {
						this.showdeletes = false
						this.recordlist()
						console.log(res)
					}
				})
			},
		
			refundconfirm() {
				console.log(this.OrderNumber)
				this.$request("pay", "refund", {
					OrderNo: this.OrderNumber
				}).then(res => {
					if (res.code == 1) {
						this.showrefund = false
						this.recordlist()
						console.log(res)
					}
				})
			},
			confirm() {
				console.log(this.OrderNumber)
				this.$request("Order", "Cancel", {
					OrderNo: this.OrderNumber
				}).then(res => {
					if (res.code == 1) {
						this.deleteshow = false
						console.log(res)
					}
				})
			},
			removes(OrderNumber) {
				this.OrderNumber = OrderNumber
				this.deleteshow = true
			},
			refund(OrderNumber) {
				this.OrderNumber = OrderNumber
				this.showrefund = true
			},
			deletesd(OrderNumber) {
				this.showdeletes = true
				this.OrderNumber = OrderNumber
			},

			recordlist() {
			//	console.log(this.list[this.current].Status)
				uni.showLoading({
					title: '加载中'
				})
				// this.Status = "2"
				this.$request("tj", "GetReport", {
				
				}).then(res => {
				//	let list = []
					if (res.code == 1) {
						console.log(res.data)

						this.orderlist = res.data.resultdata
						if (this.orderlist.length != 0) {
							this.show = true
							// this.year=this.formattedDateyear(res.data.rows[0].VisitDay)
							// this.month=this.formattedDatemonth(res.data.rows[0].VisitDay)
							// this.day=this.formattedDateday(res.data.rows[0].VisitDay)
						} else {
							this.show = false
						}
						console.log("6666666666")
						uni.hideLoading();
						console.log(res)
					}
					else
					{uni.hideLoading();
						this.show = false
					}
				})
			}
		}
	}
</script>

<style>
	@import './Health.css'
</style>